using System;
using System.Text;
using System.Runtime.InteropServices;

namespace MSRI.ActiveSyncServices
{
    class ActiveSyncLibrary
    {
    }

    [ComImport(), Guid("499C0C20-A766-11cf-8011-00A0C90A8F78")]
    public class DccMan
    {
    }
    [ComImport(), Guid("A7B88841-A812-11cf-8011-00A0C90A8F78"),
        InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IDccMan
    {
        int Advise(IDccManSink pDccSink, ref int dwContext);
        int Unadvise(int dwContext);
        void ShowCommSettings();
        void AutoconnectEnable();
        void AutoconnectDisable();
        void ConnectNow();
        void DisconnectNow();
        void SetIconDataTransferring();
        void SetIconNoDataTransferring();
        void SetIconError();
    }

    [Guid("A7B88840-A812-11cf-8011-00A0C90A8F78"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IDccManSink
    {
        [PreserveSig()]
        int OnLogIpAddr([InAttribute()] int dwIpAddr);
        [PreserveSig()]
        int OnLogTerminated();
        [PreserveSig()]
        int OnLogActive();
        [PreserveSig()]
        int OnLogInactive();
        [PreserveSig()]
        int OnLogAnswered();
        [PreserveSig()]
        int OnLogListen();
        [PreserveSig()]
        int OnLogDisconnection();
        [PreserveSig()]
        int OnLogError();
    }
    [Guid("C6659361-1625-4746-931C-36014B146679")]
    public class DccManSink : IDccManSink
    {

        [Serializable()]
        [ComVisible(true)]
        public delegate void ActiveHandler();

        [Serializable()]
        [ComVisible(true)]
        public delegate void DisconnectHandler();

        [Serializable()]
        [ComVisible(true)]
        public delegate void OnLogIpAddrHandler(int dwIpAddr);

        public event ActiveHandler Active;
        public event DisconnectHandler Disconnect;
        public event OnLogIpAddrHandler ConnectedToIPaddress;

        #region IDccManSink Members

        public int OnLogIpAddr(int dwIpAddr)
        {
            if (ConnectedToIPaddress != null)
                ConnectedToIPaddress(dwIpAddr);
            return 0;
        }

        public int OnLogTerminated()
        {
            return 0;

        }

        public int OnLogActive()
        {
            if (Active != null)
                Active();
            return 0;
        }

        public int OnLogInactive()
        {
            return 0;

        }

        public int OnLogAnswered()
        {
            return 0;

        }

        public int OnLogListen()
        {
            return 0;

        }

        public int OnLogDisconnection()
        {
            if (Disconnect != null)
                Disconnect();
            return 0;
        }

        public int OnLogError()
        {
            return 0;

        }

        #endregion
    }
}
